#include <bits/stdc++.h>
using namespace std;
#define int long long

int tmp[502], dp[53][53], lj[53][53];
char dig[53];
const int p = 1e9 + 7;

long long qpow(long long a, long long b) {
	long long res = 1;
	while (b) {
		if (b & 1) res = res * a % p;
		b >>= 1;
		a = a * a % p;
	}
	return res;
}

int C(int n, int m) {
	if (n < 0 || m < 0) return 0;
	return lj[n][m];
}

int dfs(int rem, int now, int dm, int len, int realrem) {
	if (rem < 0) return 0;
	if (now == 10) return rem == 0;
	if (dp[rem][now] != -1) return dp[rem][now];
	if (now == dm) return dfs(rem - len, now + 1, dm, len, realrem - (len - tmp[dm])) * C(realrem - (len - tmp[dm]), len - tmp[dm]) % p;
	int ans = 0;
	for (int j = tmp[now]; j <= rem; ++j) {
		if (j > len || (j == len && now > dm)) continue;
		(ans += dfs(rem - j, now + 1, dm, len, realrem - (j - tmp[now])) * C(realrem - (j - tmp[now]), j - tmp[now]) % p) %= p;
	}
	return dp[rem][now] =  ans;
}

int solve1(int n, int realrem) { // 用于求解长度为 N，确定部分的 m 所有值
	int ans = 0;
	for (int i = 0; i <= 9; ++i) { // 枚举 Digit mode
		for (int j = tmp[i]; j <= n; ++j) { // 枚举出现次数，任何数字不得超过
			memset(dp, 255, sizeof(dp));
			(ans += i * dfs(n, 0, i, j, realrem) % p) %= p;
		}
	}
	return ans;
}
int cnt[12];
void solve() {
	memset(cnt, 0, sizeof(cnt));
	scanf("%s", dig + 1);
	int n = strlen(dig + 1);
	for (int i = 1; i <= n; ++i) {
		cnt[dig[i] - '0']++;
	}
	int sum = 0;
	for (int i = 1; i < n; ++i) { //
		for (int j = 1; j <= 9; ++j) {
			memset(tmp, 0, sizeof(tmp));
			tmp[j] = 1;
			(sum += solve1(i, i - 1)) %= p;
		}
	}
	// do something
	memset(tmp, 0, sizeof(tmp));
	for (int i = 1; i <= n; ++i) {
		for (int j = (i == 1); j < dig[i] - '0'; ++j) {
			tmp[j]++;
			(sum += solve1(n, n - i)) %= p;
			tmp[j]--;
		}
		tmp[dig[i] - '0']++;
	}
	int maxn = 0;
	for (int i = 1; i <= 9; ++i) {
		if (cnt[i] >= cnt[maxn]) maxn = i;
	}
	cout << (sum + maxn) % p<< "\n";
}



signed main() {
	freopen("give.in", "r", stdin);
	freopen("give.out", "w", stdout);
	lj[0][0] = 1;
	for (int i = 0; i <= 51; ++i) {
		for (int j = 0; j <= 51; ++j) {
			if (i) lj[i][j] += lj[i - 1][j];
			if (j) lj[i][j] += lj[i][j - 1];
			lj[i][j] %= p;
		}
	}
	int tc; scanf("%lld", &tc); while (tc--) solve();
	return 0;
}
